package com.devicemantra.coordinate.interfaces.http;

import java.io.BufferedReader;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.devicemantra.coordinate.exceptions.operations.CReadPayloadException;
import com.devicemantra.coordinate.exceptions.operations.CWritePayloadException;


public class CHttpWriter 
{
	private static String mContentType;
	/* If the client forgets to set the content type use the default */
	static {
		mContentType = "text/xml";
	}
	
	public static void setContentType(String pContentType)
	{
		mContentType = pContentType;
	}
	
	public static void writeAsString(HttpServletResponse pHttpServletResponse, String pResponseStr) throws CWritePayloadException
	{
		try {
			pHttpServletResponse.setContentType(mContentType);
			pHttpServletResponse.getWriter().write(pResponseStr);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new CWritePayloadException("ERROR: Caught I/O exception : " + e.getMessage());
		} catch (NullPointerException e) {
			System.out.println("Caught : NullPointer Exception");
			throw new CWritePayloadException("ERROR: Caught Null Pointer Exception  : " + e.getMessage());
			
		} 
		
		
	}
	
	
	
}
